/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* E.P. Scene Graph
* Developed by:
*       - Eduardo Ribeiro (eribeiro @ tecgraf . puc-rio . br)
*       - Peter Dam (peter @ tecgraf . puc-rio . br)
* File: Vec4.h
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef _EPSG_VEC4_
#define _EPSG_VEC4_

#include "EPSG/Vec3.h"

namespace EPSG
{
	template <typename T>
	class Vec4
	{
	public:
		/* [CONSTRUCTOR] */	Vec4();
		/* [CONSTRUCTOR] */	Vec4( T x, T y, T z, T w );

		void				operator=( const Vec4& rhs );
		void				operator=( const Vec3<T>& rhs );
		T&					operator[]( int index );

		T*					asArray();
		
		T					x;
		T					y;
		T					z;
		T					w;

	private:
		T					invalid;
		T					arr[4];
	};
}

/* TEMPLATE METHODS */
template <typename T>
EPSG::Vec4<T>::Vec4() : x( 0 ), y( 0 ), z( 0 ), w( 0 )
{

}

template <typename T>
EPSG::Vec4<T>::Vec4( T x, T y, T z, T w )
{
	this->x = x;
	this->y = y;
	this->z = z;
	this->w = w;
}

/* OPERATORS */
template <typename T>
void EPSG::Vec4<T>::operator=( const Vec4& rhs )
{
	x = rhs.x;
	y = rhs.y;
	z = rhs.z;
	w = rhs.w;
}

template <typename T>
void EPSG::Vec4<T>::operator=( const Vec3<T>& rhs )
{
	x = rhs.x;
	y = rhs.y;
	z = rhs.z;
}

template <typename T>
T& EPSG::Vec4<T>::operator[]( int index )
{
	switch( index )
	{
	case 0:
		return x;
	case 1:
		return y;
	case 2:
		return z;
	case 3:
		return w;
	default:
		return invalid;
	}
}

template <typename T>
T* EPSG::Vec4<T>::asArray()
{
	for( int i = 0; i < 4; i++ )
		arr[i] = (*this)[i];

	return arr;
}

#endif //_EPSG_VEC4_